<?php
declare (strict_types = 1);

namespace app\api\model;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * @mixin \think\Model
 */
class Type extends Model
{
    use SoftDelete;
    public static function getType()
    {
        return self::with(['attr','spec','spec.specValue'])->select();
    }
    /**
     * 模型与属性的关系：一个模型对应多个属性
     * @return \think\model\relation\HasMany
     */
    public function attr(){
        return $this->hasMany(Attribute::class,"type_id");
    }
    /**
     * 模型与属性的关系：一个模型对应多个属性
     * @return \think\model\relation\HasMany
     */
    public function spec(){
        return $this->hasMany(Spec::class,"type_id");
    }
    /**
     * 删除指定的模型
     * @param $id
     * @return bool
     */
    public static function deleteType($id){
        return self::destroy($id);
    }

    /**
     * 商品模型入库
     * @param $data
     * @return Type|Model
     */
    public static function addType($data){
        return self::create($data,['type_name']);
    }

}
